package com.java1412.controller.admin;

import com.java1412.entity.User;
import com.java1412.service.UserService;
import com.java1412.utils.ResponseUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 后台管理员接口
 *
 * @author java1412
 * @since 2023-06-21 17:02:35
 */
@RestController
@RequestMapping("/admin/user")
//@CrossOrigin
public class AdminUserController {
    @Resource
    private UserService userService;

    @PostMapping("/login")
    public Object login(@RequestBody User user) {
        ResponseUtil r = userService.adminFindByUsername(user);
        return r;
    }

    /**
     * 分页查询
     *
     * @param currentPage 第几页
     * @param pageSize    页大小
     * @return
     */
    @GetMapping
    public Object list(
            @RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage,
            @RequestParam(value = "pageSize", required = false, defaultValue = "2") Integer pageSize
    ) {
        ResponseUtil r = userService.find(currentPage, pageSize);
        return r;
    }
}
